package tool

import java.io.File

import play.api.mvc.RequestHeader
import tool.Pojo.MissionIdFileData

/**
 * Created by yz on 28/10/2020
 */
trait MissionFileTool {

  def getUserMissionDir(userId: Int):File = {
    val userIdDir = Tool.getUserIdDir(userId)
    new File(userIdDir, "mission")
  }

  def getUserMissionDir(implicit request: RequestHeader):File = {
    val userId = Tool.getUserId
    getUserMissionDir(userId)
  }

  def getMissionWorkspaceDir(fileData: MissionIdFileData) = {
    val missionIdDir = getMissionIdDir(fileData)
    new File(missionIdDir, "workspace")
  }

  def getUserMissionKindDir(kind: String)(implicit request: RequestHeader) = {
    val userMissionDir = getUserMissionDir
    new File(userMissionDir, kind)
  }

  def getUserMissionKindDir(userId: Int, kind: String) = {
    val userMissionDir = getUserMissionDir(userId)
    new File(userMissionDir, kind)
  }

  def getMissionIdDir(fileData: MissionIdFileData) = {
    val userMissionKindDir = getUserMissionKindDir(fileData.userId, fileData.kind)
    new File(userMissionKindDir, fileData.missionId.toString)
  }

  def getMissionResultDir(fileData: MissionIdFileData) = {
    val missionIdDir = getMissionIdDir(fileData)
    new File(missionIdDir, "result")
  }

}
